﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using ZhiAo.Management;
using System.Data;
using ZhiAo.WebLib.Data;

/// <summary>
///DdlDataBind 的摘要说明
/// </summary>
public class DdlDataBind
{
    public DdlDataBind()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    public static void BindType(DropDownList drpType)
    {
        //if (RoleRight.HasRight("A0013"))
        drpType.Items.Add(new ListItem("水位", "A0013"));

        //if (RoleRight.HasRight("A0012"))
        drpType.Items.Add(new ListItem("雨量", "A0012"));
        //if (RoleRight.HasRight("A0011"))
        //    drpType.Items.Add(new ListItem("氯度", "A0011"));
        //if (RoleRight.HasRight("A0015"))
        //    drpType.Items.Add(new ListItem("蒸发", "A0015"));

        //if (RoleRight.HasRight("A00141"))
        //    drpType.Items.Add(new ListItem("气压", "A00141"));
        //if (RoleRight.HasRight("A00143"))
        //    drpType.Items.Add(new ListItem("风速", "A00143"));
        //if (RoleRight.HasRight("A00142"))
        //    drpType.Items.Add(new ListItem("温度", "A00142"));
        //if (RoleRight.HasRight("A00144"))
        //    drpType.Items.Add(new ListItem("风向", "A00144"));
        //if (RoleRight.HasRight("A00145"))
        //    drpType.Items.Add(new ListItem("湿度", "A00145"));
    }

    public static void BindData(DropDownList ddl, DataTable dt, bool needAllSelect)
    {
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem("全部", ""));
        foreach (DataRow dr in dt.Rows)
        {
            ddl.Items.Add(new ListItem(dr["itemText"].ToString(), dr["itemValue"].ToString()));
        }
    }

    public static void BindCityData(DropDownList ddlCity)
    {
        string sql = "select distinct shi itemText, shi itemValue from dbo.GeneralReport where shi is not null and shi<>''";
        DataTable dt = DBHelper.GetDataTable(sql);
        BindData(ddlCity, dt, true);
    }

    public static void BindXianData(DropDownList ddlXian, string shi)
    {
        string sql = "select distinct xian itemText, xian itemValue from dbo.GeneralReport"+ 
                     " where xian is not null and xian<>'' and shi='" + shi.Trim() + "'";
        DataTable dt = DBHelper.GetDataTable(sql);
        BindData(ddlXian, dt, true);
    }

}
